<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head :: common_head(~{::title},~{})">
  <title>财税风险分析系统  | 纳税申报表</title>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <div th:replace="common/header-user :: header"></div>
  
  <div th:replace="common/aside-user :: aside"></div>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
  
    <section class="content-header">
      <h1 id="page-title" active-aside="analysis-aside" active-menu="enterprise-income-tax-return-menu">企业所得税纳税申报表
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li class="active"><i class="fa fa-list"></i> 企业所得税纳税申报表</a></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">
      <div class="row">
        <form class="form-horizontal">
          <div class="form-group">
            <label for="enterpriseId" class="col-sm-1 control-label">企业</label>
            <div class="col-sm-6">
              <select class="form-control" name="enterpriseId">
                <option value="">请选择</option>
                <option th:each="e : ${enterprises}" th:value="${e.id}"  th:text="${e.name}" th:selected="${e.id == enterpriseId}">1</option>
              </select>
            </div>
            <div class="col-sm-5">
              <button type="button" class="btn btn-primary" id="select-enterprise-btn">确定</button>
            </div>
          </div>
        </form>
      </div>
      <div class="row">
        <!-- <div class="col-sm-3">
          <div class="info-box" style="cursor: pointer;">
            <span class="info-box-icon bg-green"><i class="fa fa-check"></i></span>
            <div class="info-box-content">
              <span class="info-box-number">2017年度</span>
              <span class="info-box-text">&nbsp;</span>
              <span class="info-box-text">已完成</span>
            </div>
            /.info-box-content
          </div>
          /.info-box
        </div>
        <div class="col-sm-3">
          <div class="info-box">
            <span class="info-box-icon bg-yellow"><i class="fa fa-star-o"></i></span>
            <div class="info-box-content">
              <span class="info-box-number">2018年度</span>
              <span class="info-box-text">&nbsp;</span>
              <span class="info-box-text">未完成</span>
            </div>
            /.info-box-content
          </div>
          /.info-box
        </div> -->
        
        <div class="col-sm-3" th:each="reportGroup : ${reportGroupList}">
          <div class="info-box info-box-group" th:attr="query_uri=@{/client/report/tax/list/}+${reportGroup.id}">
            <span class="info-box-icon bg-yellow"><i class="fa fa-star-o"></i></span>
            <div class="info-box-content">
            	
              <span class="info-box-number" th:if="${#strings.equalsIgnoreCase(reportGroup.period,'ANNUAL')}">
              [[${#temporals.year(reportGroup.startDate)}]]年度
              </span>
              
              <span class="info-box-text">&nbsp;</span>
              <span class="info-box-text" th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.completeStatus,'init')}">初始化</span>
              <span class="info-box-text" th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.completeStatus,'uncompleted')}">未完成</span>
              <span class="info-box-text" th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.completeStatus,'completed')}">已完成</span>
            </div>
          </div>
        </div>
        
        <div class="col-sm-3">
          <div class="info-box" id="info-box-add">
            <span class="info-box-icon bg-red"><i class="fa fa-plus"></i></span>
            <div class="info-box-content">
              <span class="info-box-number">&nbsp;</span>
              <span class="info-box-number">点击新增</span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
  <!-- modal begin -->
  <div class="modal fade" id="modal-add">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">纳税申报表</h4>
      </div>
      <div class="modal-body">
        <form id="addForm" th:action="@{/client/reportGroup/reportGroup}" class="form-horizontal" method="POST">
        	<input type="hidden" name="completeStatus" value="init" id="completeStatus">
          <div class="form-group">
            <label class="col-sm-2 control-label">所属日期</label>
            <div class="col-sm-10">
              <input id="startDate" autocomplete="off" class="col-sm-4 datepicker" type="text" name="startDate">
              <span class="col-sm-2" style="text-align:center">至</span>
              <input id="endDate" autocomplete="off" class="col-sm-4 datepicker" type="text" name="endDate">
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">填报类型</label>
            <div class="col-sm-10">
              <select class="form-control" name="period" id="period">
                <option value="ANNUAL">年报</option>
                <option value="SEMIANNUAL">半年报</option>
                <option value="QUARTERLY">季报</option>
                <option value="MONTHLY">月报</option>
              </select>
            </div>
          </div>
	         <div class="modal-footer">
		        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
		        <button type="button" class="btn btn-primary" id="saveBtn">保存</button>
		  	</div>
        </form>
      </div>
     <!--  <div class="modal-footer">
	        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
	        <button type="button" class="btn btn-primary" onclick="addSubmit()">保存</button>
	  </div> -->
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal end-->


  
  <div th:replace="common/footer :: footer"></div>

  <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<div th:replace="common/script :: script"></div>
<script>
  $(function() {
	  $("#select-enterprise-btn").click(function() {
      window.location.href = "/client/report/tax/index/" + $('select[name="enterpriseId"]').val();
    });
	  
    $("#info-box-add").click(function() {
    	var enterpriseId = $('select[name="enterpriseId"]').val();
      if(!enterpriseId) {
        layer.msg('请选择企业！');
        return;
      }
    	$('#modal-add').modal('show');
      	//window.location.href = "list";
    });
    
    $(".info-box-group").click(function() {
    	var _query_uri = $(this).attr("query_uri");
    	console.log(_query_uri);
    	window.location.href=_query_uri;
    });
    
    $(".datepicker").datepicker({
        language: "zh-CN",
        autoclose: true,//选中之后自动隐藏日期选择框
        clearBtn: true,//清除按钮
        todayBtn: true,//今日按钮
        format: "yyyy/mm/dd"//日期格式，
    });
    
    $("#saveBtn").click(function(){
    	var _period = $("#period").val();
    	var _startDate = $("#startDate").val();
    	var _endDate = $("#endDate").val();
    	
    	/* if(!_period){
    		layer.tips('请选择报表期', '#period');
			return false;
    	} */
    	var _monthStart = _startDate.substring(5,7);
    	var _monthEnd = _endDate.substring(5,7);
    	if(_startDate.substring(8)!='01'){
    		_startDate = _startDate.substring(0,8)+"01";
    	}
    	if(_endDate.substring(8)!='01'){
    		_endDate = _endDate.substring(0,8)+"01";
    	}
    	if(_period == "ANNUAL"){//年报
    		if(!(_startDate.substring(5,7)=="01") || !(_endDate.substring(5,7)=="12")){
    			layer.tips('请选择正确的年报时间', '#endDate');
    			return;
    		}
    	}else if(_period == "SEMIANNUAL"){//半年报
    		var quarterlyStart = ['01','06'];
    		var quarterlyEnd = ['07','12'];
    		if(quarterlyStart.indexOf(_monthStart)==-1 || quarterlyEnd.indexOf(_monthEnd)==-1){
    			layer.tips('请选择正确的半年报时间', '#endDate');
    			return;
    		}
    		
    	}else if(_period == "QUARTERLY"){//季度报
    		var quarterlyStart = ['01','04','07','10'];
    		var quarterlyEnd = ['03','06','09','12'];
    		if(quarterlyStart.indexOf(_monthStart)==-1 || quarterlyEnd.index(_monthEnd)==-1){
    			layer.tips('请选择正确的季度报时间', '#endDate');
    			return;
    		}
    	}else if(_period == "MONTHLY"){//月报
    		console.log(_startDate);
    		if(!_startDate || !(_startDate.substring(5,7) == _endDate.substring(5,7))){
    			layer.tips('请选择正确的月报时间', '#endDate');
    			return;
    		}
    	}
    	
    	var completeStatus = $("#completeStatus").val();
    	var period = $("#period").val();
    	
    	$.post("/client/reportGroup/add/ENTERPRISE_INCOME_TAX_RETURN/",
   			{
    		  'completeStatus': completeStatus,
          'period': period,
          'startDate': _startDate,
          'endDate': _endDate,
          'enterprise.id': $('select[name="enterpriseId"]').val()
    	  }, function(res) {
	    		console.log(res);
	    		if(res){
	    			location.href="/client/report/tax/list/" + res;
	    		}else{
	    			layer.msg('添加失败');
	    		}
	    	}
   	  )
    })
  });
</script>
</body>
</html>